package com.xhwl.logistics.open;


import com.xhwl.logistics.bo.cent.VehicleIntegratedConfigBO;
import com.xhwl.logistics.bo.cent.VehicleParkingInfoBO;
import com.xhwl.logistics.component.JsonConverter;
import com.xhwl.logistics.component.SignForCoSon;
import com.xhwl.logistics.dto.ResponseCommonPushCoSonDTO;
import com.xhwl.logistics.dto.push.*;
import com.xhwl.logistics.service.*;
import com.xhwl.logistics.service.cent.QueryDeviceSecondService;
import com.xhwl.logistics.service.cent.QueryDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;


@Slf4j
//@RestController
public class CoSonDataPushController {
    @Autowired
    private IVehicleAccessRecordService vehicleAccessRecordService;
    @Autowired
    private IVehiclePayRecordService vehiclePayRecordService;
    @Autowired
    private SignForCoSon signForCoSon;
    @Autowired
    private JsonConverter jsonConverter;
    @Autowired
    private QueryDeviceService queryDeviceService;
    @Autowired
    private IVehicleParkingSpaceService iVehicleParkingSpaceService;
    @Autowired
    private QueryDeviceSecondService queryDeviceSecondService;


    @PostMapping("/coson/enter-car")
    public ResponseCommonPushCoSonDTO enterCarRecord(@RequestBody CommonPushCoSonDTO<CarInDataCoSonDTO> commonPushCoSonDTO){
        CarInDataCoSonDTO data = commonPushCoSonDTO.getData();
        ResponseCommonPushCoSonDTO massage= signForCoSon.checkSign(commonPushCoSonDTO,queryDeviceService.queryAppsecretFromParkId(data.getKey()));
        if(null != massage){
            return massage;
        }
        VehicleIntegratedConfigBO vehicleIntegratedConfigBO = vehicleAccessRecordService.enterCarRecord(data);
        return signForCoSon.sign(new ResponseCommonPushCoSonDTO(),"1","ok",vehicleIntegratedConfigBO.getVehicleParkingInfoBO());
    }

    @PostMapping("/coson/out-car")
    public ResponseCommonPushCoSonDTO outCarRecord(@RequestBody CommonPushCoSonDTO<CarOutDataCoSonDTO> commonPushCoSonDTO){
        CarOutDataCoSonDTO data = commonPushCoSonDTO.getData();
        ResponseCommonPushCoSonDTO massage= signForCoSon.checkSign(commonPushCoSonDTO,queryDeviceService.queryAppsecretFromParkId(data.getKey()));
        if(null != massage){
            return massage;
        }
        VehicleIntegratedConfigBO vehicleIntegratedConfigBO = vehicleAccessRecordService.outCarRecord(data);
        return signForCoSon.sign(new ResponseCommonPushCoSonDTO(),"1","ok",vehicleIntegratedConfigBO.getVehicleParkingInfoBO());
    }

    @PostMapping("/coson/pay-order")
    public ResponseCommonPushCoSonDTO carPay(@RequestBody CommonPushCoSonDTO<CarPayDataCoSonDTO> commonPushCoSonDTO){
        CarPayDataCoSonDTO data = commonPushCoSonDTO.getData();
        ResponseCommonPushCoSonDTO massage= signForCoSon.checkSign(commonPushCoSonDTO,queryDeviceService.queryAppsecretFromParkId(data.getKey()));
        if(null != massage){
            return massage;
        }
        VehicleParkingInfoBO vehicleParkingInfoBO = vehiclePayRecordService.carPay(data);
        return signForCoSon.sign(new ResponseCommonPushCoSonDTO(),"1","ok",vehicleParkingInfoBO);
    }

    @PostMapping("/coson/send-park-space")
    public ResponseCommonPushCoSonDTO sendParkSpace(@RequestBody CommonPushCoSonDTO<CarSpaceDataCoSonDTO> commonPushCoSonDTO){
        CarSpaceDataCoSonDTO data = commonPushCoSonDTO.getData();
        ResponseCommonPushCoSonDTO massage= signForCoSon.checkSign(commonPushCoSonDTO,queryDeviceService.queryAppsecretFromParkId(data.getKey()));
        if(null != massage){
            return massage;
        }
        VehicleIntegratedConfigBO vehicleIntegratedConfigBO = iVehicleParkingSpaceService.sendparkSpace(data);
        return signForCoSon.sign(new ResponseCommonPushCoSonDTO(),"1","ok",vehicleIntegratedConfigBO.getVehicleParkingInfoBO());
    }

    @PostMapping("/coson/add-device")
    public ResponseCommonPushCoSonDTO addDevice(@RequestBody CommonPushCoSonDTO<CarDeviceDataCoSonDTO> commonPushCoSonDTO) {
        CarDeviceDataCoSonDTO data = commonPushCoSonDTO.getData();
        ResponseCommonPushCoSonDTO massage = signForCoSon.checkSign(commonPushCoSonDTO, queryDeviceService.queryAppsecretFromParkId(data.getKey()));
        if (null != massage) {
            return massage;
        }
        VehicleIntegratedConfigBO vehicleIntegratedConfigBO = queryDeviceSecondService.addDeviceCoSon(data);
        return signForCoSon.sign(new ResponseCommonPushCoSonDTO(), "1", "ok", vehicleIntegratedConfigBO.getVehicleParkingInfoBO());
    }
}


